#ifndef _BASE2chTextView_
#define _BASE2chTextView_
//-------------------------------------------------------------------------------------------------------
//      Copyright (c) 2005, Be Nanashi-San 
// 
//      Permission is hereby granted, free of charge, to any person obtaining a 
//      copy of this software and associated documentation files (the "Software"), 
//      to deal in the Software without restriction, including without limitation 
//      the rights to use, copy, modify, merge, publish, distribute, sublicense, 
//      and/or sell copies of the Software, and to permit persons to whom the 
//      Software is furnished to do so, subject to the following conditions: 
// 
//      The above copyright notice and this permission notice shall be included in 
//      all copies or substantial portions of the Software. 
// 
//      THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
//      IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
//      FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 
//      AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
//      LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
//      FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
//      DEALINGS IN THE SOFTWARE. 
// 
//      File Name:   	Base2chTextView.h
//      Author:      	Be Nanashi-San@598 in "BeOS - Zeta R4" Thread 
//						(http://pc8.2ch.net/test/read.cgi/os/1120676818/598)
//		Description:	互換Base2chTextView.
//-------------------------------------------------------------------------------------------------------

#include <TextView.h>
#include <Window.h>
#include <vector>
//#include "MonaList.h"
//#include "MUtils.h"
//#include "ObjectList.h"

enum disp_mode{
	DISP_ALL_THREAD,
	DISP_PARTIAL_THREAD
};

class BPopUpMenu;
class Base2chTextView : public BTextView
{
	public:
		Base2chTextView(BRect frame, const char *name,
					 BRect textRect,
					 uint32 resizingMode = B_FOLLOW_ALL,
					 uint32 flags = B_WILL_DRAW);
		virtual ~Base2chTextView(); 
		void AttachedToWindow();
		void FrameResized(float width, float height) {
										SetTextRect(CalcBounds(width, height)); };
		void Insert(const char *text, const text_run_array *run = NULL) {
										Insert(text, strlen(text), run); };
		void Insert(const char *text, int32 length, const text_run_array *run = NULL);
		void MakeEditable(bool editable = true);
		void MessageReceived(BMessage *msg);
		void MouseDown(BPoint where);
		void MouseUp(BPoint where);
		void MouseMoved(BPoint where, uint32 code, const BMessage *msg);
		void Pulse();
		void WindowActivated(bool state);
		void ScrollTo(BPoint point);
		inline void	ScrollTo(float x, float y) { ScrollTo(BPoint(x, y)); };
		void FindString(const char *search);
		void LoadFile(BFile *file, bool reloaded = false);
		void ScrollToRes(int32 thread_no);

		virtual void MakeFocus(bool focusState) {
										BTextView::MakeFocus(focusState);
										if (Parent()->Parent())
										(Parent()->Parent())->Invalidate(); };

	private:
		void InsertThread(int32 i, Base2chTextView *outView);
		void ClearText();
		void PostStatus(const char *title);
		void StopLoad();
		void LoadText(bool reloaded = false);

		void Seek(int32 offset, uint32 seek_mode);
		void SetDispmode(disp_mode mode);
		const disp_mode Dispmode() const;
		static int32 InsertMonaRun(void *data);
		void InsertMona();
		void HtmlParser(const char *text);
		void SetInvoke(const char *name, int32 size, int32 length);
		void SetInvoke(const char *name, int32 length);
		status_t Invoke();
		void InvokeThread(int32 thread_no);
		void SelectionInvoke();
		void Clone(int32 thread_no);
		void ThreadSelection(BPoint where, int32 &start, int32 &end);
		void UpdateThreadNo(BFile *file);
		void AddMenuItems(BPopUpMenu *menu, BPoint where);

		void PrintToStream(int32 flags = 0);
		BRect CalcBounds(float width, float height);
		int32 is_number(int32 offset);

		vector<int32>	mThread;
		MActionList	mAction;
		int32  mCursorOffset;
		int32  mCountTimer;
		int32 mMouseDown;
		thread_id mthread_id;
		bool mCancel;
		BPoint mMousePoint;
//		MonaList mDat;
//		BFile *mFile;
		BPoint static_where;
		
		int32 mCurPositon;
		disp_mode mDispmode;
};

#endif
